<?php 
$this->load->view('admin/layout/head', array('title'=>"管理员管理"), FALSE);
?>

<div id="container">
	<form class="form-inline" id="search-form" method="GET" action="">
	  <div class="form-group">
	  	<input type="text" name="keyword" value="<?= $this->input->get('keyword') ?>" class="form-control" placeholder="请输入关键词">
	  </div>
	  <button class="btn btn-info search-btn"><?= $this->lang->line('search') ?></button>
	  <a href="/admin/admins/add" class="btn btn-info">新增</a>
	</form>
	<div class="table-container mt-10">
		<table class="table table-bordered table-striped table-hover scroll-table">
			<thead >
				<tr>
					<th class="text-center">id</th>
					<th class="text-center">名称</th>
					<th class="text-center">账号</th>
					<th class="text-center"><?= $this->lang->line('status') ?></th>
					<th class="text-center"><?= $this->lang->line('actions'); ?></th>
				</tr>
			</thead>
			<tbody class="text-center">
				<?php foreach ($page as $key => $value): ?>
					<tr id="<?= $value['id'] ?>">
						<td><?= $value['id'] ?></td>
						<td><?= $value['name'] ?></td>
						<td><?= $value['account'] ?></td>
						<td><?= $value['status'] ? '禁用' : '正常' ?></td>
						<td>
							<?php if ($value['status'] == 1): ?>
								<a href="#" class="enable">启用</a>
							<?php else: ?>
								<a href="#" class="disable">禁用</a>
							<?php endif ?>
							<a href="/admin/admin/edit/<?= $value['id'] ?>">编辑</a>
						</td>
					</tr>
				<?php endforeach ?>
			</tbody>
			<?php if ($page->last_page>1): ?>
				<tfoot>
					<td colspan="10" style="text-align:right">
						<?php echo $page->render() ?>
					</td>
				</tfoot>
			<?php endif ?>
		</table>
	</div>
</div>


<?php 
$this->load->view('admin/layout/footer');
?>

<script type="text/javascript">
	function change_status(id, status)
	{
		$.ajax({
			url: '/admin/admin/change_status/'+id,
			type: 'post',
			data: {
				status: status
			},
			success: function (data) {
				alert('修改成功');
				window.location.reload();
			}
		});
	}

	$(function(){
		$('.enable').on('click', function () {
			var id = $(this).parents('tr').attr('id');
			change_status(id, 0);
		});

		$('.disable').on('click', function () {
			var id = $(this).parents('tr').attr('id');
			change_status(id, 1);
		});
	})
</script>















